﻿using System.Globalization;
using System.Windows.Data;

namespace DimensionsHelper.Client.Converters;

public class StringFormatConverter : IValueConverter
{
    public List<object> Replacements { get; set; } = [];


    public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is not string format)
        {
            return string.Empty;
        }

        try
        {
            return string.Format(format, Replacements.ToArray());
        }
        catch
        {
            return format;
        }
    }

    public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        return Binding.DoNothing;
    }
}